package cn.tedu.egarticle.base.exception;

import cn.tedu.egarticle.base.response.JsonResult;
import cn.tedu.egarticle.base.response.StatusCode;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(RuntimeException.class)
    public JsonResult runtimeException(RuntimeException e) {
        String msg = e.getMessage();

        return new JsonResult(StatusCode.NOT_LOGIN,msg);

    }
    @ExceptionHandler(MethodArgumentNotValidException.class)
    public JsonResult methodArgumentNotValidException(MethodArgumentNotValidException e) {
        String msg = e.getMessage();

        return new JsonResult(StatusCode.VALIDATED_ERROR,msg);
    }
}
